//# sourceURL=http://uMapApp/Module/SoundBench/SoundBench
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../../UI/Layer"
    , "../../Earth/ViewPort"
    , "../StakeNum/StakeNum"
], function (
    mhjs,
    uMap,
    uEarth,
    Layer,
    ViewPort,
    StakeNum
) {

    function SoundBench(option) {
        var _this = this;
        option && _this.OptionToProperties(option);

        _this.startStakeNum = StakeNum.transform(_this["开始桩号"]);
        _this.stopStakeNum = StakeNum.transform(_this["结束桩号"]);

        _this.stakeNum = _this.startStakeNum;

        _this.title = _this["开始桩号"] + " > " + _this["结束桩号"] + " / " + _this["朝向"];

        _this.searchKey = _this["开始桩号"] + " " + _this["朝向"];
        _this.sortKey = _this.startStakeNum.distance;


        if (_this.dataSource) {

            _this.layer = new Layer({
                "app"       : _this.app,
                "dataSource": _this.dataSource
            });

            _this.layer.dataSourceView.on("loaded", function () {

                // _this.layer.dataSourceView.close();

                _this.position = _this.layer.viewport.center;

                _this.layer.viewport.hpr = {
                    "heading": _this["朝向"] === "上行" ? 0 : 180,
                    "pitch"  : -15,
                    "range"  : 100
                };

                _this.marker = new uMap.Entity({
                    objectOption: {
                        position : _this.position,
                        billboard: new uMap.BillboardGraphic({
                            objectOption: {
                                image                   : _this.app.icons.getIconMarker(_this.icon),
                                verticalOrigin          : "BOTTOM",
                                disableDepthTestDistance: Number.POSITIVE_INFINITY
                            }
                        }),
                        label    : new uMap.LabelGraphic({
                            objectOption: {
                                text                    : _this["编号"],
                                verticalOrigin          : "TOP",
                                disableDepthTestDistance: Number.POSITIVE_INFINITY
                            }
                        })
                    }
                });
                _this.layer.dataSources.entities.add(_this.marker.object);

                _this.marker.on("click", function () {
                    _this.trigger("click");
                });

            });


        }


    }

    var _class = SoundBench;

    mhjs.OptionToPropertiesInterface(_class);
    mhjs.EventInterface(_class);

    Object.defineProperties(_class.prototype, {
        "open"  : {
            value: function () {
                if (!this.isOpened) {
                    this.layer && this.layer.open();
                    this.isOpened = true;
                    this.trigger("open");
                }
            }
        },
        "close" : {
            value: function () {
                if (this.isOpened) {
                    this.layer && this.layer.close();
                    this.isOpened = false;
                    this.trigger("close");
                }
            }
        },
        "toggle": {
            value: function () {
                if (this.isOpened) {
                    this.close();
                } else {
                    this.open();
                }
            }
        },
        "active": {
            value: function (isActive) {
                var _this = this;

                isActive = (isActive === undefined) || Boolean(isActive);
                _this.isActive = _this.isActive === undefined ? false : _this.isActive;

                if (isActive !== _this.isActive) {

                    if (isActive) {

                        if (_this.layer) {
                            // _this.layer.active();
                            // _this.layer.dataSourceView.open();
                        }

                        if (_this.marker) {
                            _this.marker.label.fillColor = new uMap.Color(["#ff0"]);
                            _this.marker.label.scale = 1.2;
                            _this.marker.billboard.scale = 1.2;
                        }


                        _this.trigger("active");
                    } else {


                        if (_this.layer) {
                            // _this.layer.dataSourceView.close();
                        }

                        if (_this.marker) {
                            _this.marker.label.fillColor = new uMap.Color(["#fff"]);
                            _this.marker.label.scale = 1;
                            _this.marker.billboard.scale = 1;
                        }

                        _this.trigger("unActive");
                    }

                    _this.isActive = isActive;

                }

            }
        }
    });

    return _class;

});